﻿var PaymentCalculator = function(){

    // calculate
    function calculate(data){

        jQuery.ajax({
            type: 'GET',
            contentType: "application/json; charset=utf-8",
            dataType: 'jsonp',
            data: Json2.stringify(data, null),
            url: "http://localhost:49000/services/request/calculators/standardloan/",
            cache: false

        });      
          
    }

    function init(){
        // Set up the widget container
        var container = "";
        container += '<table id="widgetForm">';
        container += '<tbody>';
        container += '<tr>';
        container += '<td width="100%">Loan Amount</td>';
        container += '<td class="input">$<input id="form_loanAmount" value="16000" size="8" name="loanAmount"></td></tr>';
        container += '<tr>';
        container += '<td>Loan Term: (months)</td>';
        container += '<td class="input">(60-120) <input id="form_termMonths" value="60" size=8 name="termMonths"></td></tr>';
        container += '<tr>';
        container += '<td>Interest Rate</td>';
        container += '<td class="input">%<input id="form_interestrate" value="5.000" size=8 name="interestrate"></td></tr>';
        container += '</tbody></table>';
        container += '<a id="calculate" >Calculate</a>';    
        container += '</div>';    
        jQuery("#widgetContainer").prepend(container);
        // Attach event handler

    }

    return{
        Initlize: init,
        Calculate: calculate
    }

}();

//
// Initilize Widget
//-------------------------------------------------------------------------------------------
jQuery(document).ready(function(){

    PaymentCalculator.Initlize();

});